package leetcode;

import java.util.List;

public class LC21 {

    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
       ListNode  newListHead = new ListNode(200,null);
       ListNode newListPre = newListHead;
       while (list1 != null && list2 != null) {
           if (list1.val < list2.val) {
               newListPre.next = list1;
               list1 = list1.next;
           } else {
               newListPre.next = list2;
               list2 = list2.next;
           }
           newListPre = newListPre.next;
       }
       newListPre.next = list1 == null ? list2 : list1;
       return newListHead.next;
    }
}
class ListNode {
     int val;
     ListNode next;
     ListNode() {}
     ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }
